package com.baymax.test.scene.demo

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.life.SecondActivity
import com.baymax.test.scene.newSceneFlexContainer
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class LaunchModeScene : BaseScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return p1.newSceneFlexContainer {
            val intent = Intent(requireActivity(), SecondActivity::class.java)

            addButton("reset") {
                intent.setFlags(0)
            }
            addButton("newTask") {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            addButton("clearTop") {
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            }
            addButton("start>>") {
                requireActivity().startActivity(intent)
            }

            addButton("start>> delay 2s") {
                launch {
                    delay(2000)
                    requireActivity().startActivity(intent)
                }
            }
        }
    }
}